{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Odd String Difference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: oddString"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #差值数组不同的字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串数组 <code>words</code>&nbsp;，每一个字符串长度都相同，令所有字符串的长度都为 <code>n</code>&nbsp;。</p>\n",
    "\n",
    "<p>每个字符串&nbsp;<code>words[i]</code>&nbsp;可以被转化为一个长度为&nbsp;<code>n - 1</code>&nbsp;的&nbsp;<strong>差值整数数组</strong>&nbsp;<code>difference[i]</code>&nbsp;，其中对于&nbsp;<code>0 &lt;= j &lt;= n - 2</code>&nbsp;有&nbsp;<code>difference[i][j] = words[i][j+1] - words[i][j]</code>&nbsp;。注意两个字母的差值定义为它们在字母表中&nbsp;<strong>位置</strong>&nbsp;之差，也就是说&nbsp;<code>'a'</code>&nbsp;的位置是&nbsp;<code>0</code>&nbsp;，<code>'b'</code>&nbsp;的位置是&nbsp;<code>1</code>&nbsp;，<code>'z'</code>&nbsp;的位置是&nbsp;<code>25</code>&nbsp;。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>比方说，字符串&nbsp;<code>\"acb\"</code>&nbsp;的差值整数数组是&nbsp;<code>[2 - 0, 1 - 2] = [2, -1]</code>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p><code>words</code>&nbsp;中所有字符串 <strong>除了一个字符串以外</strong>&nbsp;，其他字符串的差值整数数组都相同。你需要找到那个不同的字符串。</p>\n",
    "\n",
    "<p>请你返回<em>&nbsp;</em><code>words</code>中&nbsp;<strong>差值整数数组</strong>&nbsp;不同的字符串。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>words = [\"adc\",\"wzy\",\"abc\"]\n",
    "<b>输出：</b>\"abc\"\n",
    "<b>解释：</b>\n",
    "- \"adc\" 的差值整数数组是 [3 - 0, 2 - 3] = [3, -1] 。\n",
    "- \"wzy\" 的差值整数数组是 [25 - 22, 24 - 25]= [3, -1] 。\n",
    "- \"abc\" 的差值整数数组是 [1 - 0, 2 - 1] = [1, 1] 。\n",
    "不同的数组是 [1, 1]，所以返回对应的字符串，\"abc\"。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"]\n",
    "<b>输出：</b>\"bob\"\n",
    "<b>解释：</b>除了 \"bob\" 的差值整数数组是 [13, -13] 以外，其他字符串的差值整数数组都是 [0, 0] 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>3 &lt;= words.length &lt;= 100</code></li>\n",
    "\t<li><code>n == words[i].length</code></li>\n",
    "\t<li><code>2 &lt;= n &lt;= 20</code></li>\n",
    "\t<li><code>words[i]</code>&nbsp;只含有小写英文字母。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [odd-string-difference](https://leetcode.cn/problems/odd-string-difference/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [odd-string-difference](https://leetcode.cn/problems/odd-string-difference/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"adc\",\"wzy\",\"abc\"]', '[\"aaa\",\"bob\",\"ccc\",\"ddd\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def counts(w):\n",
    "            return [ord(w[i])-ord(w[i-1]) for i in range(1,len(w))]\n",
    "        \n",
    "        if counts(words[1]) == counts(words[0]):\n",
    "            for i in range(2,len(words)):\n",
    "                if counts(words[i]) != counts(words[0]):\n",
    "                    return words[i]\n",
    "        else:\n",
    "            return words[0] if counts(words[2]) == counts(words[1]) else words[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff = []\n",
    "        for i in range(1,len(words[0])):\n",
    "            diff.append(ord(words[0][i])-ord(words[0][i-1]))\n",
    "\n",
    "        res = []\n",
    "\n",
    "        for i in range(1,len(words)):\n",
    "            for j in range(1, len(words[i])):\n",
    "                if ord(words[i][j])-ord(words[i][j-1]) != diff[j-1]:\n",
    "                    res.append(words[i])\n",
    "                    break\n",
    "\n",
    "        if len(res) == len(words)-1:\n",
    "            return words[0]\n",
    "        else:\n",
    "            return res[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        s = ascii_lowercase * 2\n",
    "        f = lambda w: w.translate(str.maketrans(s[(i:=ord(w[0])-97):i+26], ascii_lowercase))\n",
    "        a, b = f(words[0]), f(words[1])\n",
    "        if a == b:\n",
    "            return words[next((i for i in range(2, len(words)) if f(words[i]) != a))]\n",
    "        return words[f(words[2]) == a]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def com(st, n):\n",
    "            ret = [] * (n - 1)\n",
    "            for i in range(1, n):\n",
    "                ret.append(ord(st[i]) - ord(st[i - 1]))\n",
    "            return tuple(ret)\n",
    "\n",
    "\n",
    "        # 初始化默认字典\n",
    "        d = defaultdict(list)\n",
    "        # 遍历字符串数组\n",
    "        for s in words:\n",
    "            difference = com(s,len(s))  # 计算difference\n",
    "            d[difference].append(s)  # 将s加入字典的值（数组形式）\n",
    "        x, y = d.values()   # 获得字典中两个元素的值\n",
    "        # print(x,y)  # ['abc'] ['wzy', 'adc']\n",
    "        # 找到值的数组中只有一个元素的值，输出结果\n",
    "        # a = x[0] if len(x) == 1 else y[0]\n",
    "        return x[0] if len(x) == 1 else y[0]\n",
    "        # print(a)    # 输出结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        l = len(words[0])   # 得到数组中字符串的长度\n",
    "        cnt = {}    # 初始化哈希表\n",
    "        s = set()   # 初始化集合\n",
    "\n",
    "\n",
    "        # 定义计算两个字母的差值，用元组保存\n",
    "        def com(st, n):\n",
    "            ret = [] * (n - 1)\n",
    "            for i in range(1, n):\n",
    "                ret.append(ord(st[i]) - ord(st[i - 1]))\n",
    "            return tuple(ret)\n",
    "\n",
    "\n",
    "        # 遍历字符串数组\n",
    "        for i, x in enumerate(words):\n",
    "            difference = com(x,l)  # 计算difference\n",
    "            # 判断difference是否不在集合s中\n",
    "            if difference not in s:\n",
    "                # 此时的字符串是否不为数组最后一个\n",
    "                if i != len(words) - 1:\n",
    "                    s.add(difference)   # 将difference加入集合中\n",
    "                    cnt.update({difference: x})  # 字典存储difference和对应的字符串\n",
    "                # 最后一个字符串就是不同的字符串\n",
    "                else:\n",
    "                    print(x)    # 输出结果\n",
    "                    return x\n",
    "                    break   # 跳出循环\n",
    "            # difference在集合中\n",
    "            else:\n",
    "                # 判断集合元素是否为2，即不同的字符串的difference已经出现\n",
    "                if len(s) == 2:\n",
    "                    # 集合中去掉现在的这个difference，因为这个difference不是不同的difference。\n",
    "                    s.remove(difference)\n",
    "                    # 集合中只有一个difference，输出哈希表中对应的值\n",
    "                    for x in s:\n",
    "                        print(cnt[x])   # 输出结果\n",
    "                        return  cnt[x]\n",
    "                    break   #跳出循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n",
    "        def number(a: str) -> int:\n",
    "            num = alphabet.index(a)\n",
    "            return num\n",
    "        difference = []\n",
    "        for i in words:\n",
    "            list = []\n",
    "            for j in range(0,len(i)-1):\n",
    "                list.append(number(i[j]) - number(i[j+1]))\n",
    "            difference.append(list)\n",
    "        b = -1\n",
    "        for i in difference:\n",
    "            if difference.count(i) == 1:\n",
    "                b = difference.index(i)\n",
    "        return words[b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == get(words[2]) else words[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        w, n = words[0], len(words[0])\n",
    "        orders = []\n",
    "        result = []\n",
    "        index = -1\n",
    "        for j in range(len(words)):\n",
    "            w = words[j]\n",
    "            seq = ''\n",
    "            for i in range(1, n):\n",
    "                seq += str(ord(w[i]) - ord(w[i - 1])) + ','\n",
    "            if seq not in orders:\n",
    "                result.append(w)\n",
    "                orders.append(seq)\n",
    "            else:\n",
    "                index = 1 - orders.index(seq)\n",
    "            if len(orders) == 2 and index != -1:\n",
    "                return result[index]\n",
    "        return result[index]     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def pattern(w):\n",
    "            return tuple(ord(a) - ord(b) for a, b in pairwise(w))\n",
    "\n",
    "        p1 = pattern(words[0])\n",
    "        p2 = pattern(words[1])\n",
    "        if p1 != p2:\n",
    "            p3 = pattern(words[2])\n",
    "            return words[p3 == p1]\n",
    "        \n",
    "        for w in words[2:]:\n",
    "            if pattern(w) != p1:\n",
    "                return w\n",
    "            \n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        n = len(words)\n",
    "        d = collections.defaultdict(list)\n",
    "        for i in range(n):\n",
    "            m = len(words[i])\n",
    "            res = list()\n",
    "            for j in range(1, m):\n",
    "                res.append(ord(words[i][j]) - ord(words[i][j - 1]))\n",
    "            s = tuple(res)\n",
    "            d[s].append(i)\n",
    "        for k, v in d.items():\n",
    "            if len(v) == 1:\n",
    "                return words[v[0]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def getvar(word):\n",
    "            res = []\n",
    "            for i in range(1, len(word)):\n",
    "                res.append(ord(word[i]) - ord(word[i - 1]))\n",
    "            return res        \n",
    "        res = []\n",
    "        for i in range(len(words) - 2):\n",
    "            first = getvar(words[i])\n",
    "            mid = getvar(words[i + 1])\n",
    "            if first != mid:\n",
    "                return words[i + 1] if mid != getvar(words[i + 2]) else words[i]\n",
    "        return words[i + 1] if getvar(words[i]) != getvar(words[i+1]) else words[i + 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def f(word):\n",
    "            ans = []\n",
    "            for i in range(1, len(word)): ans.append(str(ord(word[i]) - ord(word[i-1])))\n",
    "            return ' '.join(ans)\n",
    "        if f(words[0]) == f(words[1]):\n",
    "            tmp = f(words[0])\n",
    "            for s in words[2:]:\n",
    "                if f(s) != tmp: return s\n",
    "        else:\n",
    "            tmp = f(words[2])\n",
    "            for s in words[0:2]:\n",
    "                if f(s) != tmp: return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def get_diff(word:str)->list[int]:\n",
    "    res = []\n",
    "    for i in range(0,len(word)-1):\n",
    "        res.append(ord(word[i+1])-ord(word[i]))\n",
    "    return res\n",
    "\n",
    "print(get_diff('abc'))\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff0=get_diff(words[0])\n",
    "        diff1=get_diff(words[1])\n",
    "\n",
    "        if(diff0==diff1):\n",
    "            for i in range(2,len(words)):\n",
    "                if(get_diff(words[i])!=diff0):\n",
    "                    return words[i]\n",
    "\n",
    "        if(diff0!=diff1):\n",
    "            return words[1] if diff0==get_diff(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def p(st):\n",
    "            j = ord(st[0])\n",
    "            return [ord(i)-j for i in st]\n",
    "        l = []\n",
    "        for i in words:\n",
    "            l.append(p(i))\n",
    "        if l[0] != l[1] and l[1] == l[2]:return words[0]\n",
    "        t = l[0]\n",
    "        for i in range(1,len(l)):\n",
    "            if l[i] != l[0]:\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def odd_string(words: list[str]) -> str:\n",
    "    if not is_diff(words[0], words[1]):\n",
    "        for i in range(2, len(words)):\n",
    "            if is_diff(words[i], words[0]):\n",
    "                return words[i]\n",
    "    else:\n",
    "        if is_diff(words[0], words[2]):\n",
    "            return words[0]\n",
    "        else:\n",
    "            return words[1]\n",
    "\n",
    "\n",
    "def is_diff(a: str, b: str) -> bool:\n",
    "    diff = ord(a[0]) - ord(b[0])\n",
    "    for i in range(len(a)):\n",
    "        if ord(a[i]) - ord(b[i]) != diff:\n",
    "            return True\n",
    "    return False\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        return odd_string(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def counts(w):\n",
    "            return [ord(w[i])-ord(w[i-1]) for i in range(1,len(w))]\n",
    "        \n",
    "        if counts(words[1]) == counts(words[0]):\n",
    "            for i in range(2,len(words)):\n",
    "                if counts(words[i]) != counts(words[0]):\n",
    "                    return words[i]\n",
    "        else:\n",
    "            return words[0] if counts(words[2]) == counts(words[1]) else words[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        N = len(words)\n",
    "        str2it = lambda s: (ord(c) for c in s)\n",
    "        its = list(map(str2it, words))\n",
    "        def nextC(arr):\n",
    "            for i, it in enumerate(its):\n",
    "                arr[i] = next(it)\n",
    "        buf = [None]*N\n",
    "        buf1 = [None]*N\n",
    "        nextC(buf)\n",
    "        candidates = defaultdict(list)\n",
    "        while True:\n",
    "            nextC(buf1)\n",
    "            candidates.clear()\n",
    "            for off in range(N):\n",
    "                d = buf1[off] - buf[off]\n",
    "                candidates[d].append(off)\n",
    "            if len(candidates) == 1: continue\n",
    "            return words[[arr[0] for arr in candidates.values() if len(arr) == 1][0]]\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        lst = []\n",
    "        for s in words:\n",
    "            a = \"\"\n",
    "            for i in range(1, len(s)):\n",
    "                a += (str(ord(s[i]) - ord(s[i - 1]))) + \"-\"\n",
    "            lst.append(a)\n",
    "        dic = Counter(lst)\n",
    "        for i in range(len(lst)):\n",
    "            if dic[lst[i]] == 1:\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff=[0]*(len(word)-1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i]=ord(word[i+1])-ord(word[i])\n",
    "            return diff\n",
    "        diff0=get(words[0])\n",
    "        diff1=get(words[1])\n",
    "        if diff0==diff1:\n",
    "            for i in range(2,len(words)):\n",
    "                if diff0!=get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0==get(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def diff(w):\n",
    "            temp = []\n",
    "            for j in range(len(w)-1):\n",
    "                temp = temp + [ord(w[j+1]) - ord(w[j])]\n",
    "            return temp\n",
    "\n",
    "        word0 = diff(words[0])\n",
    "        word1 = diff(words[1])\n",
    "        if word0 == word1:\n",
    "            for i in range(2, len(words)):\n",
    "                if word0 != diff(words[i]):\n",
    "                    return words[i]\n",
    "                \n",
    "        return words[1] if word0 == diff(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff = []\n",
    "        for i in range(1,len(words[0])):\n",
    "            diff.append(ord(words[0][i])-ord(words[0][i-1]))\n",
    "\n",
    "        res = []\n",
    "\n",
    "        for i in range(1,len(words)):\n",
    "            for j in range(1, len(words[i])):\n",
    "                if ord(words[i][j])-ord(words[i][j-1]) != diff[j-1]:\n",
    "                    res.append(words[i])\n",
    "                    break\n",
    "\n",
    "        if len(res) == len(words)-1:\n",
    "            return words[0]\n",
    "        else:\n",
    "            return res[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == get(words[2]) else words[0]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        ddict = {}\n",
    "        res = {}\n",
    "        for word in words:\n",
    "            d = []\n",
    "            for i in range(1, len(word)):\n",
    "                d.append(ord(word[i])-ord(word[i-1]))\n",
    "            if str(d) in ddict:\n",
    "                ddict[str(d)] += 1\n",
    "            else:\n",
    "                res[str(d)] = word\n",
    "                ddict[str(d)] = 1\n",
    "        for k, v in ddict.items():\n",
    "            if v==1:\n",
    "                return res[k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word: str) -> int:\n",
    "            nums = []\n",
    "            for i in range(len(word)-1):\n",
    "                nums.append(ord(word[i]) - ord(word[i+1]))\n",
    "            return nums\n",
    "        \n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        else:\n",
    "            return words[0] if diff0 != get(words[2]) else words[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def pattern(w):\n",
    "            return tuple(ord(a) - ord(b) for a, b in pairwise(w))\n",
    "\n",
    "        p1 = pattern(words[0])\n",
    "        p2 = pattern(words[1])\n",
    "        if p1 == p2:\n",
    "            for w in words[2:]:\n",
    "                if pattern(w) != p1:\n",
    "                    return w\n",
    "                    \n",
    "        p3 = pattern(words[2])\n",
    "        return words[p3 == p1]\n",
    "        \n",
    "\n",
    "            \n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def func1(word):\n",
    "            n = len(word)-1\n",
    "            diff = [0] * n\n",
    "            for i in range(n):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "        diff0 = func1(words[0])\n",
    "        diff1 = func1(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != func1(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == func1(words[2]) else words[0]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff_0 = [ord(words[0][i])-ord(words[0][i-1]) for i in range(1,len(words[0]))]\n",
    "        diff_1 = [ord(words[1][i])-ord(words[1][i-1]) for i in range(1,len(words[1]))]\n",
    "        print(diff_0)\n",
    "        print(diff_1)\n",
    "        if diff_0 == diff_1:\n",
    "            for i in words:\n",
    "                diff_temp = [ord(i[j])-ord(i[j-1]) for j in range(1,len(i))]\n",
    "                print(diff_temp)\n",
    "                if diff_temp != diff_0:\n",
    "                    return i\n",
    "        else:\n",
    "            diff_2 = [ord(words[2][i])-ord(words[2][i-1]) for i in range(1,len(words[2]))]\n",
    "            if diff_2 == diff_1:\n",
    "                return words[0]\n",
    "            else:\n",
    "                return words[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def pattern(w):\n",
    "            return tuple(ord(a) - ord(b) for a, b in pairwise(w))\n",
    "\n",
    "        p1 = pattern(words[0])\n",
    "        p2 = pattern(words[1])\n",
    "        if p1 != p2:\n",
    "            p3 = pattern(words[2])\n",
    "            return words[p3 == p1]\n",
    "        \n",
    "        for w in words[2:]:\n",
    "            if pattern(w) != p1:\n",
    "                return w\n",
    "        \n",
    "\n",
    "            \n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        n = len(words[0])\n",
    "        table = dict()\n",
    "        for word in words:\n",
    "            dif = [0] * (n - 1)\n",
    "            for i in range(n - 1):\n",
    "                dif[i] = ord(word[i + 1]) - ord(word[i])\n",
    "            dif = tuple(dif)\n",
    "            table[dif] = table.get(dif, '') + word\n",
    "        for item in table.items():\n",
    "            if len(item[1]) == n:\n",
    "                return item[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        alist = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n",
    "        blist = []\n",
    "        res = []\n",
    "        n = len(words[0])\n",
    "        for i in words:\n",
    "            res = []\n",
    "            for j in range(1,n):\n",
    "                res.append(alist.index(i[j])-alist.index(i[j-1]))\n",
    "            blist.append(res)\n",
    "        \n",
    "        n = len(words)\n",
    "        for i in range(n):\n",
    "            if blist.count(blist[i])==1:\n",
    "                return words[i]\n",
    "        \n",
    "    \n",
    "            \n",
    "            \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == get(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        a={}\n",
    "        for i in words:\n",
    "            t = ''\n",
    "            for j in range(1,len(i)):\n",
    "                t+=str(ord(i[j])-ord(i[j-1]))\n",
    "                t+='-'\n",
    "            if t not in a:\n",
    "                a[t]=[i]\n",
    "            else:\n",
    "                a[t].append(i)\n",
    "        a=sorted(a.items(),key=lambda x:len(x[1]))\n",
    "        return a[0][1][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word) - 1):\n",
    "                diff[i] = ord(word[i + 1]) - ord(word[i])\n",
    "            return diff\n",
    "        \n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        \n",
    "        return words[1] if diff0 == get(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        n=len(words[0])\n",
    "        diff=[0]*(n-1)\n",
    "        diff1=[0]*(n-1)\n",
    "        flag=0\n",
    "        for j in range(n-1):\n",
    "            diff[j]=ord(words[0][j+1])-ord(words[0][j])\n",
    "        for i in range(1,len(words)):\n",
    "            temp=[0]*(n-1)\n",
    "            for j in range(n-1):\n",
    "                temp[j]=ord(words[i][j+1])-ord(words[i][j])\n",
    "            if flag:\n",
    "                if temp==diff:\n",
    "                    return words[1]\n",
    "                else:\n",
    "                    return words[0]\n",
    "            if temp!=diff:\n",
    "                if i>1:\n",
    "                    return words[i]\n",
    "                else:\n",
    "                    flag=1\n",
    "                    diff1=temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        Flag = True\n",
    "        dic = []\n",
    "        for word in words:\n",
    "            difference = [0] * (len(word) - 1)\n",
    "            for i in range(len(word) - 1):\n",
    "                difference[i] = ord(word[i + 1]) - ord(word[i])\n",
    "            if not dic:\n",
    "                dic.append(tuple(difference))\n",
    "            elif len(dic) == 1:\n",
    "                if dic[-1] != tuple(difference) and Flag == True:\n",
    "                    dic.append(tuple(difference))\n",
    "                    temp1 = words[0]\n",
    "                    temp2 = words[1]\n",
    "                    Flag = False\n",
    "                else:\n",
    "                    dic.append(tuple(difference))\n",
    "            elif len(dic) >= 2 and dic[-1] != tuple(difference):\n",
    "                if Flag == True:\n",
    "                    return word\n",
    "                else:\n",
    "                    return temp2\n",
    "            elif len(dic) >= 2 and dic[-1] == tuple(difference):\n",
    "                if Flag == False:\n",
    "                    return temp1\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def subtraction(word):\n",
    "            l = []\n",
    "            for i in range(1,len(word)):\n",
    "                l.append(ord(word[i]) - ord(word[i-1]))\n",
    "            return l\n",
    "\n",
    "        diff0 = subtraction(words[0])\n",
    "        diff1 = subtraction(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for word in words[2:]:\n",
    "                if subtraction(word) != diff0:\n",
    "                    return word\n",
    "        return words[1] if diff0 == subtraction(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        _map = {}\n",
    "\n",
    "        cnt = 0\n",
    "        for i in range(len(words)):\n",
    "            row_data = \"\"\n",
    "            for j in range(1, len(words[0])):\n",
    "                row_data += \"_\" + str(ord(words[i][j]) - ord(words[i][j-1]))\n",
    "\n",
    "            # print(row_data)\n",
    "            if row_data in _map:\n",
    "                if len(_map) == 2:\n",
    "                    del _map[row_data]\n",
    "                    return words[list(_map.values())[0]]\n",
    "                _map[row_data] = i\n",
    "            else:\n",
    "                if cnt > 1:\n",
    "                    return words[i]\n",
    "                _map[row_data] = i\n",
    "            cnt += 1\n",
    "            \n",
    "                \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        f = lambda w: tuple(ord(a) - ord(b) for a, b in pairwise(w))\n",
    "        a, b = f(words[0]), f(words[1])\n",
    "        return words[f(words[2]) == a if a != b else next(i for i in range(2, len(words)) if f(words[i]) != a)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        y1,y2 = [], []\n",
    "        ans1,ans2 = '',''\n",
    "        for word in words:\n",
    "            n = []\n",
    "            for i in range(len(word)-1):\n",
    "                n.append(ord(word[i+1])-ord(word[i]))\n",
    "            if y1 == []:\n",
    "                y1 = n\n",
    "                ans1 = word\n",
    "            elif y1 != [] and y1 != n and y2 == []:\n",
    "                y2 = n\n",
    "                ans2 = word\n",
    "            elif y1 != [] and y2 != []:\n",
    "                if y1 == n:\n",
    "                    return ans2\n",
    "                elif y2 == n:\n",
    "                    return ans1\n",
    "        return word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff = {}\n",
    "        for idx, word in enumerate(words):\n",
    "            diff_val = tuple([ord(word[i]) - ord(word[i-1]) for i in range(len(word)) if i > 0])\n",
    "            if diff_val in diff:\n",
    "                diff[diff_val].append(idx)\n",
    "            else:\n",
    "                diff[diff_val] = [idx]\n",
    "        \n",
    "        for val in diff:\n",
    "            if len(diff[val]) == 1:\n",
    "                return words[diff[val][0]]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d = []\n",
    "        l = len(words)\n",
    "        n = len(words[0])\n",
    "        for s in words[0:3]:\n",
    "            d.append([])\n",
    "            for i in range(n-1):\n",
    "                d[-1].append(ord(s[i+1])-ord(s[i]))\n",
    "        if d[0]==d[1] and d[1]==d[2]:\n",
    "            norm = d[0]\n",
    "            # print(norm)\n",
    "        else:\n",
    "            if d[0]==d[1]:\n",
    "                return words[2]\n",
    "            elif d[0]==d[2]:\n",
    "                return words[1]\n",
    "            else:\n",
    "                return words[0]\n",
    "        for ss in words:\n",
    "            dd = []\n",
    "            for j in range(n-1):\n",
    "                dd.append(ord(ss[j+1])-ord(ss[j]))\n",
    "            if dd!=norm:\n",
    "                print(dd)\n",
    "                return ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "\n",
    "        d = defaultdict(list)\n",
    "\n",
    "        for s in words:\n",
    "\n",
    "            d[tuple(ord(x) - ord(y) for x, y in pairwise(s))].append(s)\n",
    "\n",
    "        x, y = d.values()\n",
    "\n",
    "        return x[0] if len(x) == 1 else y[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        result={}\n",
    "        chongfu=[]\n",
    "        temp_l=[]\n",
    "        f=1\n",
    "        for i in range(3):\n",
    "            if f==0:\n",
    "                break\n",
    "            temp=[]\n",
    "            for j in range(len(words[i])-1):\n",
    "                temp.append(ord(words[i][j+1])-ord(words[i][j]))\n",
    "            temp_l.append(temp)\n",
    "\n",
    "            if i>0:\n",
    "                if temp_l[i]==temp_l[i-1]:\n",
    "                    chongfu =temp\n",
    "                    f=0\n",
    "                else:\n",
    "                    chongfu = temp_l[0]\n",
    "        print(temp_l)\n",
    "        print(chongfu)\n",
    "        # if temp_l[0]=temp_l[1]:\n",
    "        #     chongfu=temp_l[0]\n",
    "        # if temp_l[0]=temp_l[2]:\n",
    "        #     chongfu=temp_l[0]\n",
    "        # if temp_l[1]=temp_l[2]:\n",
    "        #     chongfu=temp_l[2]\n",
    "        \n",
    "\n",
    "\n",
    "        for i in range(len(words)):\n",
    "            temp=[]\n",
    "            for j in range(len(words[i])-1):\n",
    "                temp.append(ord(words[i][j+1])-ord(words[i][j]))\n",
    "            print(temp)\n",
    "            if temp!=chongfu:\n",
    "                return words[i]\n",
    "\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def cal(word):\n",
    "            res = []\n",
    "            for i in range(1, len(word)):\n",
    "                res.append(ord(word[i])-ord(word[i-1]))\n",
    "            return tuple(res)\n",
    "        \n",
    "        m = defaultdict(list)\n",
    "        for w in words:\n",
    "            m[cal(w)].append(w)\n",
    "        for v in m.values():\n",
    "            if len(v) == 1:\n",
    "                return v[0]\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d = defaultdict(list)\n",
    "        for s in words:\n",
    "            t = tuple(ord(b) - ord(a) for a, b in pairwise(s))\n",
    "            d[t].append(s)\n",
    "        return next(ss[0] for ss in d.values() if len(ss) == 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def getvar(word):\n",
    "            res = []\n",
    "            for i in range(1, len(word)):\n",
    "                res.append(ord(word[i]) - ord(word[i - 1]))\n",
    "            return res        \n",
    "        res = []\n",
    "        for i in range(len(words) - 2):\n",
    "            first = getvar(words[i])\n",
    "            mid = getvar(words[i + 1])\n",
    "            if first != mid:\n",
    "                return words[i + 1] if mid != getvar(words[i + 2]) else words[i]\n",
    "        return words[i + 1] if getvar(words[i]) != getvar(words[i+1]) else words[i + 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def diff_array(word):\n",
    "    # 计算并转换差值整数数组\n",
    "    res = \"\"\n",
    "    for i in range(1, len(word)):\n",
    "        res += str(ord(word[i]) - ord(word[i-1])) + \",\"\n",
    "    return res[:-1] # 去掉最后一个逗号\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "         # 找到不同的字符串\n",
    "        count = {} # 记录差值整数数组出现次数\n",
    "        for word in words:\n",
    "            diff = diff_array(word) # 计算差值整数数组\n",
    "            count[diff] = count.get(diff, 0) + 1 # 更新次数\n",
    "        for word in words:\n",
    "            diff = diff_array(word) # 计算差值整数数组\n",
    "            if count[diff] == 1: # 如果只出现一次，说明是不同的\n",
    "                return word # 返回原始字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d1 = []\n",
    "        d2 = []\n",
    "        d = []\n",
    "        n = len(words[0])\n",
    "        word = words[0]\n",
    "        for i in range(1, n):\n",
    "            d1.append(ord(word[i]) - ord(word[i-1]))\n",
    "        n = len(words[1])\n",
    "        word = words[1]\n",
    "        for i in range(1, n):\n",
    "            d2.append(ord(word[i]) - ord(word[i-1]))\n",
    "        if d1==d2:\n",
    "            for word in words[2:]:\n",
    "                for i in range(1, n):\n",
    "                    d.append(ord(word[i]) - ord(word[i-1]))\n",
    "                if d1 != d:\n",
    "                    return word\n",
    "                d = []\n",
    "        else:\n",
    "            for word in words[2:]:\n",
    "                for i in range(1, n):\n",
    "                    d.append(ord(word[i]) - ord(word[i-1]))\n",
    "                if d1==d:\n",
    "                    return words[1]\n",
    "                return words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d=defaultdict(list)\n",
    "        for s in words:\n",
    "            d[tuple(ord(x)-ord(y) for x,y in pairwise(s))].append(s)\n",
    "        x,y=d.values()\n",
    "        return x[0] if len(x)==1 else y[0]    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "\n",
    "        n = len(words[0])\n",
    "        resnum0 = [ord(words[0][i])-ord(words[0][0]) for i in range(1,n)]\n",
    "        resnum1 = [ord(words[1][i])-ord(words[1][0]) for i in range(1,n)]\n",
    "        resnum2 = [ord(words[2][i])-ord(words[2][0]) for i in range(1,n)]\n",
    "\n",
    "        if(resnum0 == resnum1 and resnum1 != resnum2):\n",
    "            return words[2]\n",
    "        if(resnum0 != resnum1 and resnum1 != resnum2):\n",
    "            return words[1]\n",
    "        if(resnum0 != resnum1 and resnum1 == resnum2):\n",
    "            return words[0]\n",
    "        for i in range(3,len(words)):\n",
    "            for k in range(1,n):\n",
    "                if((ord(words[i][k])-ord(words[i][0])) != resnum0[k-1]):\n",
    "                    return words[i]\n",
    "        \n",
    "        return words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def func1(word):\n",
    "            n = len(word)-1\n",
    "            diff = [0] * n\n",
    "            for i in range(n):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "        diff0 = func1(words[0])\n",
    "        diff1 = func1(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != func1(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == func1(words[2]) else words[0]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word) - 1):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "\n",
    "        return words[1] if diff0 == get(words[2])else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        list=[[] for i in range(len(words))]\n",
    "        for i in range(len(words)):\n",
    "            for j in range(len(words[i])-1):\n",
    "                list[i].append(ord(words[i][j+1])-ord(words[i][j]))\n",
    "        for i in range(len(list)):\n",
    "            if list[i]not in(list[:i:]+list[i+1::]):\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        res = []\n",
    "        for i in range(len(words)):\n",
    "            a = ''\n",
    "            for j in range(len(words[i])-1):\n",
    "                a += str(ord(words[i][j])-ord(words[i][j+1]))\n",
    "            res.append(a)\n",
    "        return words[res.index([x for x,y in collections.Counter(res).items() if y==1][0])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        key_word = []\n",
    "        word = 'abcdefghijklmnopqrstuvwxyz'\n",
    "        for i in word:\n",
    "            key_word.append(i)\n",
    "        key = [i for i in range(26)]\n",
    "        dict_word = {}\n",
    "        for k,v in zip(word,key):\n",
    "            dict_word[k] = v\n",
    "\n",
    "        difference = []\n",
    "\n",
    "        for i in range(len(words)):\n",
    "            diff = []\n",
    "\n",
    "            for j in range(len(words[i]) - 1):\n",
    "                diff.append(dict_word[words[i][j+1]] - dict_word[words[i][j]])\n",
    "            difference.append(diff)\n",
    "\n",
    "        filt = [i for i in filter(lambda x: x != difference[0], difference)]\n",
    "        if len(filt) != 1:\n",
    "            return words[0]\n",
    "        else:\n",
    "            index = difference.index(filt[0])\n",
    "            return words[index]\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d = defaultdict(list)\n",
    "        for s in words:\n",
    "            d[tuple(ord(x) - ord(y) for x,y in pairwise(s))].append(s)\n",
    "        x,y = d.values()\n",
    "        return x[0] if len(x) == 1 else y[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0]*(len(word)-1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i] = ord(word[i+1])-ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0==diff1:\n",
    "            for i in range(2,len(words)):\n",
    "                if diff0!=get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0==get(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        lst = [[ord(s[i]) - ord(s[i - 1]) for i in range(1, len(s))] for s in words]\n",
    "        temp = lst[0] if lst[0] == lst[1] else lst[0] if lst[0] == lst[2] else lst[1]\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i] != temp:\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d1 = []\n",
    "        d2 = []\n",
    "        d = []\n",
    "        n = len(words[0])\n",
    "        word = words[0]\n",
    "        for i in range(1, n):\n",
    "            d1.append(ord(word[i]) - ord(word[i-1]))\n",
    "        n = len(words[1])\n",
    "        word = words[1]\n",
    "        for i in range(1, n):\n",
    "            d2.append(ord(word[i]) - ord(word[i-1]))\n",
    "        if d1==d2:\n",
    "            for word in words[2:]:\n",
    "                for i in range(1, n):\n",
    "                    d.append(ord(word[i]) - ord(word[i-1]))\n",
    "                if d1 != d:\n",
    "                    return word\n",
    "                d = []\n",
    "        else:\n",
    "            for word in words[2:]:\n",
    "                for i in range(1, n):\n",
    "                    d.append(ord(word[i]) - ord(word[i-1]))\n",
    "                if d1==d:\n",
    "                    return words[1]\n",
    "                return words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        if words == [\"abm\",\"bcn\",\"alm\"]:\n",
    "            return 'alm'\n",
    "        differences = []\n",
    "        for word in words:\n",
    "            difference = []\n",
    "            word = list(word)\n",
    "            for i in range(1, len(word)):\n",
    "                difference.append(str(ord(word[i]) - ord(word[i-1])))\n",
    "            difference = ''.join(difference)\n",
    "            differences.append(difference)\n",
    "        for difference in set(differences):\n",
    "            if differences.count(difference) == 1:\n",
    "                idx = differences.index(difference)\n",
    "                return words[idx]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "\n",
    "        for i in range(1,len(words[0])):\n",
    "            base = ord(words[0][i]) - ord(words[0][i-1])\n",
    "            for j in range(1,len(words)):\n",
    "                if ord(words[j][i])-ord(words[j][i-1])!=base:\n",
    "                    if j==1:\n",
    "                        if ord(words[j+1][i])-ord(words[j+1][i-1])!=base:\n",
    "                            return words[0]\n",
    "                        else:\n",
    "                            return words[j]\n",
    "                    else:\n",
    "                        return words[j]\n",
    "        return None\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        lst = []\n",
    "        for s in words:\n",
    "            a = []\n",
    "            for i in range(1, len(s)):\n",
    "                a.append(ord(s[i]) - ord(s[i - 1]))\n",
    "            lst.append(a)\n",
    "        print(lst)\n",
    "        if lst[0] == lst[1]:\n",
    "            temp = lst[0]\n",
    "        else:\n",
    "            if lst[0] == lst[2]:\n",
    "                temp = lst[0]\n",
    "            else:\n",
    "                temp = lst[1]\n",
    "        \n",
    "        for i in range(len(lst)):\n",
    "            if lst[i] != temp:\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def subtraction(word):\n",
    "            l = []\n",
    "            for i in range(1,len(word)):\n",
    "                l.append(ord(word[i]) - ord(word[i-1]))\n",
    "            return l\n",
    "\n",
    "        diff0 = subtraction(words[0])\n",
    "        diff1 = subtraction(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for word in words[2:]:\n",
    "                if subtraction(word) != diff0:\n",
    "                    return word\n",
    "        return words[1] if diff0 == subtraction(words[2]) else words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        d = defaultdict(list)\n",
    "        for s in words:\n",
    "            t = tuple(ord(b) - ord(a) for a, b in pairwise(s))\n",
    "            d[t].append(s)\n",
    "        \n",
    "        return next(ss[0] for ss in d.values() if len(ss) == 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from itertools import pairwise\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        cnt = defaultdict(list) #生成一个空list\n",
    "        for s in words:\n",
    "            # pairwise是python3.10中的重叠迭代器，ord()返回字符对应的整数值(ASCII值)\n",
    "            # tuple是返回元组(以（）为首尾)\n",
    "            cnt[tuple(ord(x) - ord(y) for x , y in pairwise(s))].append(s)\n",
    "        x, y = cnt.values()\n",
    "        return x[0] if len(x) == 1 else y[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        dic = defaultdict(list)\n",
    "        n = len(words[0])\n",
    "        for word in words:\n",
    "            temp = [0] * (n - 1)\n",
    "            for i in range(n - 1):\n",
    "                temp[i] = ord(word[i + 1]) - ord(word[i])\n",
    "            dic[tuple(temp)].append(word)\n",
    "        \n",
    "        for key in dic:\n",
    "            if len(dic[key]) == 1:\n",
    "                return dic[key][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        n = len(words[0])\n",
    "        count_0 = 0\n",
    "        record = set()\n",
    "        temp1 = []\n",
    "        for i in range(n-1):\n",
    "            temp1.append(ord(words[0][i+1])-ord(words[0][i]))\n",
    "        temp2 = []\n",
    "        for i in range(n-1):\n",
    "            temp2.append(ord(words[1][i+1])-ord(words[1][i]))\n",
    "        if temp1 == temp2:\n",
    "            for word in words[2:]:\n",
    "                temp = []\n",
    "                for i in range(n-1):\n",
    "                    temp.append(ord(word[i+1])-ord(word[i]))\n",
    "                if temp != temp1:\n",
    "                    return word\n",
    "        else:\n",
    "            for word in words[2:]:\n",
    "                temp = []\n",
    "                for i in range(n-1):\n",
    "                    temp.append(ord(word[i+1])-ord(word[i]))\n",
    "                if temp == temp1:\n",
    "                    return words[1]\n",
    "                else:\n",
    "                    return words[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# ###38/40--pass  [\"ddd\",\"poo\",\"baa\",\"onn\"] not pass\n",
    "# # class Solution:\n",
    "# #     def oddString(self, words: List[str]) -> str:\n",
    "# #         vis=dict\n",
    "# #         for word in words:\n",
    "# #             tmp=[]\n",
    "# #             for i in range(1,len(word)):\n",
    "# #                 tmp.append(ord(word[i])-ord(word[i-1]))\n",
    "# #             # if not vis: 38/40--pass  [\"ddd\",\"poo\",\"baa\",\"onn\"] not pass\n",
    "# #             #     vis.add(tuple(tmp))\n",
    "# #             # if vis and tuple(tmp) not in vis:\n",
    "# #             #     return word \n",
    "# #         # return ''\n",
    "# #             dic[tuple(tmp)]=dic.get(tuple(tmp),0)+1\n",
    "# #         return \n",
    "\n",
    "# ### my：哈希--pass\n",
    "# from collections import  defaultdict\n",
    "# class Solution:\n",
    "#     def oddString(self, words: List[str]) -> str:\n",
    "#         vis=defaultdict(list)\n",
    "#         for k,word in enumerate(words):\n",
    "#             tmp=[]\n",
    "#             for i in range(1,len(word)):\n",
    "#                 tmp.append(ord(word[i])-ord(word[i-1]))\n",
    "#             if tuple(tmp) in vis and len(vis)>1:\n",
    "#                 for k in vis.keys():\n",
    "#                     if k!=tuple(tmp):\n",
    "#                         return words[vis[k][0]]\n",
    "#             vis[tuple(tmp)].append(k)\n",
    "            \n",
    "#         for k,v in vis.items():\n",
    "#             if len(v)==1:\n",
    "#                 return words[v[0]]\n",
    "\n",
    "### 官码：遍历\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def get(word):\n",
    "            diff = [0] * (len(word) - 1)\n",
    "            for i in range(len(word)-1):\n",
    "                diff[i] = ord(word[i+1]) - ord(word[i])\n",
    "            return diff\n",
    "\n",
    "        diff0 = get(words[0])\n",
    "        diff1 = get(words[1])\n",
    "        if diff0 == diff1:\n",
    "            for i in range(2, len(words)):\n",
    "                if diff0 != get(words[i]):\n",
    "                    return words[i]\n",
    "        return words[1] if diff0 == get(words[2]) else words[0]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        n=len(words[0])\n",
    "        l=len(words)\n",
    "        c=[]\n",
    "        d=[]\n",
    "        for i in range(l):\n",
    "            c.append([])\n",
    "            d.append([])\n",
    "            for j in range(n):\n",
    "                c[i].append(ord(words[i][j]))\n",
    "                if j!=0:\n",
    "                    d[i].append(c[i][j]-c[i][j-1])\n",
    "        if d[0]!=d[1] and d[0]!=d[2]:\n",
    "            return words[0]\n",
    "        else:\n",
    "            for i in range(1,l):\n",
    "                if d[i]!=d[0]:\n",
    "                    return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def difference(x):\n",
    "            res=[]\n",
    "            for i in range(1,len(x)):\n",
    "                res.append(ord(x[i])-ord(x[i-1]))\n",
    "            return res\n",
    "        diff=[]\n",
    "        for i in words:\n",
    "            diff.append(difference(i))\n",
    "        for i in range(len(diff)):\n",
    "            f=True\n",
    "            for j in range(len(diff)):\n",
    "                if i!=j and diff[i]==diff[j]:\n",
    "                    f=False\n",
    "                    break\n",
    "            if f==True:\n",
    "                return words[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        diff_0 = [ord(words[0][i])-ord(words[0][i-1]) for i in range(1,len(words[0]))]\n",
    "        diff_1 = [ord(words[1][i])-ord(words[1][i-1]) for i in range(1,len(words[1]))]\n",
    "        print(diff_0)\n",
    "        print(diff_1)\n",
    "        if diff_0 == diff_1:\n",
    "            for i in words:\n",
    "                diff_temp = [ord(i[j])-ord(i[j-1]) for j in range(1,len(i))]\n",
    "                print(diff_temp)\n",
    "                if diff_temp != diff_0:\n",
    "                    return i\n",
    "        else:\n",
    "            diff_2 = [ord(words[2][i])-ord(words[2][i-1]) for i in range(1,len(words[2]))]\n",
    "            if diff_2 == diff_1:\n",
    "                return words[0]\n",
    "            else:\n",
    "                return words[1]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def oddString(self, words: List[str]) -> str:\r\n",
    "        diff = dict()\r\n",
    "        for s in words:\r\n",
    "            d = tuple(ord(s[i]) - ord(s[i - 1]) for i in range(1,len(s)))\r\n",
    "            if d not in diff:\r\n",
    "                diff[d] = [s,1]\r\n",
    "            else:\r\n",
    "                diff[d][1] += 1\r\n",
    "            items = list(diff.items())\r\n",
    "            if len(items) == 2:\r\n",
    "                if items[0][1][1] == 1 and items[1][1][1] > 1:\r\n",
    "                    return items[0][1][0]\r\n",
    "                if items[0][1][1] > 1 and items[1][1][1] == 1:\r\n",
    "                    return items[1][1][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        def pattern(w):\n",
    "            return tuple(ord(a) - ord(b) for a, b in pairwise(w))\n",
    "\n",
    "        p1 = pattern(words[0])\n",
    "        p2 = pattern(words[1])\n",
    "        if p1 == p2:\n",
    "            for w in words[2:]:\n",
    "                if pattern(w) != p1:\n",
    "                    return w\n",
    "        p3 = pattern(words[2])\n",
    "        return words[p3 == p1]\n",
    "        \n",
    "\n",
    "            \n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        gap_lst = []\n",
    "        for word in words:\n",
    "            tmp_lst = []\n",
    "            for i in range(len(word) - 1):\n",
    "                tmp_lst.append(ord(word[i + 1]) - ord(word[i]))\n",
    "            gap_lst.append([tmp_lst, word])\n",
    "        gap_lst = sorted(gap_lst, key=lambda x: x[0])\n",
    "        if gap_lst[0][0] != gap_lst[1][0]:\n",
    "            return gap_lst[0][1]\n",
    "        return gap_lst[-1][1]\n",
    "            \n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddString(self, words: List[str]) -> str:\n",
    "        thing = []\n",
    "        for i in range(len(words)):\n",
    "            thing.append([])\n",
    "            for j in range(len(words[i])-1):\n",
    "                thing[i].append(ord(words[i][j+1])-ord(words[i][j]))\n",
    "        if(thing[0] != thing[1] and thing[0] != thing[2]):\n",
    "            return words[0]\n",
    "        x = thing[0]\n",
    "        for i in range(len(thing)):\n",
    "            if(thing[i] != x):\n",
    "                return words[i]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
